//
//  BIBluetoothManager.h
//  BIBluetoothModule
//
//  Created by yown on 2022/3/5.
//

#import "BIBluetoothModel.h"

#import <BIToolModule/BIProjectDefine.h>
#import <CoreBluetooth/CoreBluetooth.h>

/// 蓝牙总状态改变的通知(主线程通知)
static NSString *const kBluetoothStateNotification = @"kBluetoothStateNotification";
/// 所有蓝牙设备列表的通知(主线程通知)
static NSString *const kAllBluetoothListNotification = @"kAllBluetoothListNotification";
/// 某个蓝牙连接状态改变的通知(主线程通知)
static NSString *const kBluetoothConnectResultNotification = @"kBluetoothConnectResultNotification";
/// 某个蓝牙读特征订阅完的通知(主线程通知)
static NSString *const kBluetoothNotifyFinishNotification = @"kBluetoothNotifyFinishNotification";
/// 蓝牙设备发送给app的数据(主线程通知)
static NSString *const kBluetoothSendDataNotification = @"kBluetoothSendDataNotification";

@interface BIBluetoothManager : NSObject

/// 蓝牙状态
@property(nonatomic, assign, readonly) CBManagerState state;
/// 扫描到的所有蓝牙设备列表的模型<BIBluetoothModel>
@property (nonatomic, readonly) NSMutableArray <BIBluetoothModel *>*allPeripherals;
/// 历史连接过的蓝牙设备列表<BIBluetoothModel>
@property (nonatomic, readonly) NSMutableArray <BIBluetoothModel *>*connectedPeripherals;
/// 当前使用的蓝牙对象
@property (nonatomic, readonly) BIBluetoothModel *currentBluetoothModel;

/// 单例声明
BISingletonInterface()

/// 蓝牙启动，将可用特征的UUID存储，方便自动连接，手动连接的匹配
/// writeUUIDS 写特征的UUID数组，key是写特征的UUID，value是设备对应的指令类
/// readUUIDS 读特征的UUID字典，key是读特征的UUID，value是设备对应的解析类
- (void)launchWithWriteUUIDS:(NSDictionary *)writeUUIDS readUUIDS:(NSDictionary *)readUUIDS;
/// 扫描蓝牙列表
- (void)scanBluetoothList;
/// 停止扫描蓝牙列表
- (void)stopScan;
/// 通过model连接蓝牙
- (void)connectBluetooth:(BIBluetoothModel *)model;
/// 通过model断开蓝牙，如果为空，则断开所有蓝牙
- (void)disconnectBluetooth:(BIBluetoothModel *)model;
/// 断开所有的蓝牙
/// 发送数据到硬件
/// - Parameters:
///   - data: 发送的数据
///   - model: 使用的设备对象，如果为空，则所有已连接设备都会发送
- (void)sendData:(NSData *)data model:(BIBluetoothModel *)model;

@end
